package com.bw.liuyushan.liuyushan20210929.MVP.Activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bw.liuyushan.liuyushan20210929.Adapter.FragmentMainAdapter;
import com.bw.liuyushan.liuyushan20210929.Entity.JsonBean;
import com.bw.liuyushan.liuyushan20210929.GreenDao.GoodBean;
import com.bw.liuyushan.liuyushan20210929.MVP.Contrack.IContrackTest;
import com.bw.liuyushan.liuyushan20210929.MVP.Fragment.HomeFragment;
import com.bw.liuyushan.liuyushan20210929.MVP.Fragment.ListFragment;
import com.bw.liuyushan.liuyushan20210929.MVP.Fragment.MineFragment;
import com.bw.liuyushan.liuyushan20210929.MVP.Fragment.ShopFragment;
import com.bw.liuyushan.liuyushan20210929.MVP.Model.BaseModelTest;
import com.bw.liuyushan.liuyushan20210929.MVP.Presenter.BasePresenterTest;
import com.bw.liuyushan.liuyushan20210929.R;
import com.bw.liuyushan.liuyushan20210929.Utils.GoodBeanUtils;
import com.bw.liuyushan.mvp_lib.View.BaseActivity;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.editorpage.ShareActivity;
import com.umeng.socialize.media.UMWeb;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * 详情页满 第三方分享
 */
public class SimItemActivity extends BaseActivity<BasePresenterTest> implements IContrackTest.C_ViewTest {


    private android.widget.ImageView imgSim;
    private android.widget.TextView tvTitle;
    private android.widget.TextView tvPrice;
    private android.widget.Button addCar;
    private Button shareCar;

    @Override
    public int bindLayout() {
        return R.layout.activity_simitem;
    }

    @Override
    public void initView() {
        //链接 防内存泄露
        mPresenter=new BasePresenterTest(new BaseModelTest(),this);

        imgSim = (ImageView) findViewById(R.id.img_sim);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvPrice = (TextView) findViewById(R.id.tv_price);
        addCar = (Button) findViewById(R.id.addCar);
        shareCar = (Button) findViewById(R.id.shareCar);
    }

    @Override
    public void initDate() {
        Intent intent = getIntent();
        JsonBean.DataBean obj = (JsonBean.DataBean) intent.getSerializableExtra("obj");
        tvTitle.setText(obj.getTitle());
        tvPrice.setText(obj.getCollect_num());
        Glide.with(getApplicationContext()).load(obj.getPic()).into(imgSim);
        addCar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread(new Runnable() {//子线程存储
                    @Override
                    public void run() {
                        GoodBean goodBean = new GoodBean();
                        goodBean.setTitle(obj.getTitle());
                        goodBean.setPrice(obj.getCollect_num());
                        goodBean.setPic(obj.getPic());
                        goodBean.setGetCheacks(false);
                        GoodBeanUtils.getInstance().getDaoSession().getGoodBeanDao().insert(goodBean);
                    }
                }).start();
                ToastUtils.showShort("已存入购物车");
            }
        });
        shareCar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UMWeb web =new UMWeb(obj.getPic());
                web.setTitle("链接地址");//标题
//                new ShareAction(SimItemActivity.this).withText("hello").withMedia(web).share();
                new ShareAction(SimItemActivity.this).withText("hello")
                        .withMedia(web)
                        .setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN)
                        .setCallback(new UMShareListener() {
                            @Override
                            public void onStart(SHARE_MEDIA share_media) {

                            }

                            @Override
                            public void onResult(SHARE_MEDIA share_media) {

                            }

                            @Override
                            public void onError(SHARE_MEDIA share_media, Throwable throwable) {

                            }

                            @Override
                            public void onCancel(SHARE_MEDIA share_media) {

                            }
                        }).open();
            }
        });

    }
}
